﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace BDSim
{
    public class MenuCommand
    {
        string _Header = "";
        Image _Icon;
        string _GestureKey ;
        bool _IsCheckable = false;
        bool _IsChecked = false;
        SimpleCommand _Command = new SimpleCommand();
        List<MenuCommand> _SubMenuCommandList = new List<MenuCommand>();

        /// <summary>
        /// 定义菜单项“选择状态更改时”执行的委托事件
        /// </summary>
        DelegateCheck CheckedEvent;

        /// <summary>
        /// 菜单项中显示的名字
        /// </summary>
        public string Header
        {
            get { return _Header; }
            set { _Header = value; }
        }

        /// <summary>
        /// 菜单项中显示的图标
        /// </summary>
        public Image Icon
        {
            get { return _Icon; }
            set { _Icon = value; }
        }

        /// <summary>
        /// 快捷键
        /// </summary>
        public string GestureKey
        {
            get { return _GestureKey; }
            set { _GestureKey = value; }
        }

        /// <summary>
        /// 菜单项是否启用选择功能
        /// </summary>
        public bool IsCheckable
        {
            get { return _IsCheckable; }
            set { _IsCheckable = value; }
        }

        /// <summary>
        /// 菜单项选择标识
        /// </summary>
        public bool IsCheckedFlag
        {
            get { return _IsChecked; }
            set
            {
                _IsChecked = value;
                if (IsCheckable && CheckedEvent!= null)
                {
                    CheckedEvent(_IsChecked);
                }
            }
        }

        
        
        /// <summary>
        /// 定义菜单项执行的事件
        /// </summary>
        public SimpleCommand ExcuteCommand
        {
            get { return _Command; }
            set { _Command = value; }
        }

        
        
        /// <summary>
        /// 定义菜单项子级菜单
        /// </summary>
        public List<MenuCommand> SubMenuCommandList
        {
            get { return _SubMenuCommandList; }
            set { _SubMenuCommandList = value; }
        }

        public void DefineExcuteCommand(Action<object> Execute)
        {
            DefineExcuteCommand(Execute, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Execute">命令执行的事件</param>
        /// <param name="canExcute">命令可执行的使能控制</param>
        public void DefineExcuteCommand(Action<object> Execute,Predicate<object> canExcute)
        {
            ExcuteCommand.ExecuteDelegate = Execute;
            ExcuteCommand.CanExecuteDelegate = canExcute;
        }

        public void DefineChecked(DelegateCheck CheckEventHandle)
        {
            CheckedEvent = CheckEventHandle;
        }
    }

    public delegate bool DelegateCanExcute();

    public delegate void DelegateExcute();

    public delegate void DelegateCheck(bool flag);
}
